import apis from "@/http/apis.js";
export default ({
    namespaced: true,
    state: {
        orders: [],
        orderForPayState: [],
        pagesData: {
            pageSize: 3,
            currentPage: 1,
            total: 0,
            pages: 0,
        },
        ordersById: []
    },
    getters: {

    },
    mutations: {
        ordersData(state, data) {
            state.orders = data.orders;
            state.pagesData.total = data.allTotal;
        },

        orderToCancel(state, data) {
            state.orderForPayState = data.toCancelOrders;
            state.pagesData.total = data.toCancelTotal;
        },

        changePageSize(state, data) {
            state.pagesData.pageSize = data
            state.pagesData.currentPage = 1

        },
        changeCurrentPage(state, data) {
            state.pagesData.currentPage = data
        },
    },

    actions: {
        async getOrders(context, search) {
            const {
                data
            } = await apis.orders.getOrders({
                ...search,
                ...context.state.pagesData,
            })
            console.log(data);
            console.log(data.orders);
            context.commit("ordersData", data)
        },


        async getToCancelOrders(context, search) {
            const {
                data
            } = await apis.orders.getOrders({
                ...search,
                ...context.state.pagesData,
            })
            console.log(data);
            context.commit("orderToCancel", data)
        },



        async disposeOrdersToCancel(context, _id) {
            const {
                data
            } = await apis.orders.disposeOrdersToCancel({
                _id
            })
            if (data.status) {
                console.log(data);
            }
        },
        
        async submitOrdersToCancel(context, _id) {
            const {
                data
            } = await apis.orders.submitOrdersToCancel({
                _id
            })
            if (data.status) {
                console.log(data);
            }
        },

        async changeOrderById(context, order) {
            const {
                data
            } = await apis.orders.changeOrderById({
               ...order
            })
            return data
        },

    },
    modules: {

    }
})